CMAKE_MINIMUM_REQUIRED( VERSION 2.6 )

PROJECT( sceneExpression )
SET( CMAKE_CONFIGURATION_TYPES "Release" CACHE INTERNAL "Build Type" FORCE )
# SET( CMAKE_BUILD_TYPE Release CACHE STRING "Options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE )

ADD_DEFINITIONS(-Wall -Wparentheses -Wno-long-long -Wno-import -Wreturn-type -Wmissing-braces -Wunknown-pragmas -Wunused)
ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC)
# ADD_DEFINITIONS(-pedantic -fvisibility=hidden)

SET( SX_HEADER_DIRECTORY  ${PROJECT_SOURCE_DIR}/libs/${PROJECT_NAME}/include )
SET( SX_SOURCE_DIRECTORY  ${PROJECT_SOURCE_DIR}/libs/${PROJECT_NAME}/src )
SET( SX_BINARY_DIRECTORY  ${PROJECT_SOURCE_DIR}/libs/${PROJECT_NAME}/bin )


# include directory for SceneExpression
INCLUDE_DIRECTORIES( ${SX_HEADER_DIRECTORY} )



# ------------ Platform specifics
IF(UNIX)
IF(APPLE)
	# OSX
	
	# Set SDK
	#
	SET( CMAKE_OSX_SYSROOT  "/Developer/SDKs/MacOSX10.5.sdk" )
	
	# Find osx frameworks
	#
	INCLUDE_DIRECTORIES( /Developer/Headers/FlatCarbon )
	FIND_LIBRARY(AGL_LIBRARY AGL)
	FIND_LIBRARY(APP_SERVICES_LIBRARY ApplicationServices )
	FIND_LIBRARY(ATBOX_LIBRARY AudioToolbox)
	FIND_LIBRARY(CARBON_LIBRARY Carbon)
	FIND_LIBRARY(CAUDIO_LIBRARY CoreAudio)
	FIND_LIBRARY(CFOUNDATION_LIBRARY CoreFoundation)
	FIND_LIBRARY(CSERVICES_LIBRARY CoreServices)
	FIND_LIBRARY(OPENGL_LIBRARY OpenGL)
	FIND_LIBRARY(QUICKTIME_LIBRARY QuickTime )

	MARK_AS_ADVANCED (AGL_LIBRARY
			 APP_SERVICES_LIBRARY
			 ATBOX_LIBRARY
			 CARBON_LIBRARY
			 CAUDIO_LIBRARY
			 CFOUNDATION_LIBRARY
			 CSERVICES_LIBRARY
			 OPENGL_LIBRARY
			 QUICKTIME_LIBRARY)
	SET(OSX_FRAMEWORKS ${AGL_LIBRARY} 
	                   ${APP_SERVICES_LIBRARY} 
	                   ${ATBOX_LIBRARY} 
	                   ${CARBON_LIBRARY} 
	                   ${CAUDIO_LIBRARY} 
	                   ${CFOUNDATION_LIBRARY} 
	                   ${CSERVICES_LIBRARY} 
	                   ${OPENGL_LIBRARY} 
	                   ${QUICKTIME_LIBRARY})
	
	
	# set the executable to build
	#
	SET(EXECUTABLE_TYPE MACOSX_BUNDLE)
	
	# include directory for OSG
	INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/libs/osg-osx/include )
		
	# set common target libs for apps
	#
	SET( TARGET_LINK_LIBRARIES
		${PROJECT_NAME}
		${OSX_FRAMEWORKS}
		${PROJECT_SOURCE_DIR}/libs/freetype-osx/lib/freetype.a	
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgViewer.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_ive.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_freetype.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_openflight.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_qt.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_rgb.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_bmp.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_osg.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_obj.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_3ds.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_dxf.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgdb_stl.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgGA.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgFX.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgTerrain.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgSim.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgText.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgDB.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosgUtil.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libosg.a 
		${PROJECT_SOURCE_DIR}/libs/osg-osx/lib/libOpenThreads.a	
	)




ELSE()
	# Linux
	
	FIND_PACKAGE(X11)
	FIND_PACKAGE(OpenGL)
	# FIND_PACKAGE(FreeType)
	FIND_PACKAGE(ZLIB)
    # FIND_PACKAGE(GIFLIB)
    FIND_PACKAGE(JPEG)
    FIND_PACKAGE(PNG)
    # FIND_PACKAGE(TIFF)
	SET( LINUX_TARGET_LIBRARIES  
		${X11_LIBRARY}
		${OpenGL_LIBRARY}
		${ZLIB_LIBRARY}
		${JPEG_LIBRARY}
		${PNG_LIBRARY}
	)
	
	# include directory for OSG
	INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/libs/osg-linux/include )
		
	# set common target libs for apps
	#
	SET( TARGET_LINK_LIBRARIES
		${PROJECT_NAME}
		pthread m GL GLU SM ICE X11 Xext Xrandr z freetype jpeg png
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgViewer.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_ive.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_freetype.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_openflight.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_rgb.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_png.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_jpeg.a
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_bmp.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_osg.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_obj.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_3ds.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_dxf.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgdb_stl.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgGA.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgFX.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgTerrain.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgSim.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgText.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgDB.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosgUtil.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libosg.a 
		${PROJECT_SOURCE_DIR}/libs/osg-linux/lib/libOpenThreads.a	
	)
ENDIF(APPLE)
ENDIF(UNIX)



IF(WIN32)
	# Windows

	# FIND_PACKAGE(OpenGL)
	# FIND_PACKAGE(FreeType)
    # FIND_PACKAGE(JPEG)
    # FIND_PACKAGE(PNG)
	# FIND_PACKAGE(ZLIB)	
	# FIND_PACKAGE(QuickTime)
	
	# include directory for OSG
	INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/libs/osg-win32/include )	
	
	# set common target libs for apps
	#
	SET( TARGET_LINK_LIBRARIES
		${PROJECT_NAME}	
		OpenGL32.lib GLu32.lib kernel32.lib setupapi.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib
		${PROJECT_SOURCE_DIR}/libs/freetype-win32/lib/freetype237.lib	
		${PROJECT_SOURCE_DIR}/libs/jpeg-win32/lib/libjpeg.lib
		${PROJECT_SOURCE_DIR}/libs/png-win32/lib/libpng13.lib
		${PROJECT_SOURCE_DIR}/libs/zlib-win32/lib/zlib1.lib
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgViewer.lib
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_ive.lib
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_freetype.lib
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_openflight.lib
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_rgb.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_png.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_jpeg.lib
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_bmp.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_osg.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_obj.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_3ds.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_dxf.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osgdb_stl.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgGA.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgFX.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgTerrain.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgSim.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgText.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgDB.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osgUtil.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/osg55-osg.lib 
		${PROJECT_SOURCE_DIR}/libs/osg-win32/lib/ot11-OpenThreads.lib	
	)
	
	SET( ZLIB_DLL_RUNTIME  ${PROJECT_SOURCE_DIR}/libs/zlib-win32/bin/zlib1.dll )
	SET( PNG_DLL_RUNTIME  ${PROJECT_SOURCE_DIR}/libs/png-win32/bin/libpng13.dll )	
ENDIF()
# ------------ end platform specifics


# file(RELATIVE_PATH variable directory file)


MACRO( POST_BUILD_COPY_FILE  source_file  target_path )
	ADD_CUSTOM_COMMAND( 
		TARGET ${EXAMPLE_NAME}
	    POST_BUILD
	    COMMAND ${CMAKE_COMMAND} -E copy
		${source_file}
	    ${target_path}
	)
ENDMACRO()



###########################################
# LIBS
###########################################

# ----------------------------------------< sceneExpression >
ADD_LIBRARY( ${PROJECT_NAME} STATIC
    ${SX_HEADER_DIRECTORY}/sx/ButtonWidget.h
    ${SX_HEADER_DIRECTORY}/sx/CheckboxWidget.h
    ${SX_HEADER_DIRECTORY}/sx/Constants.h
    ${SX_HEADER_DIRECTORY}/sx/Events.h
    ${SX_HEADER_DIRECTORY}/sx/Main.h
    ${SX_HEADER_DIRECTORY}/sx/Model.h
    ${SX_HEADER_DIRECTORY}/sx/Node.h
    ${SX_HEADER_DIRECTORY}/sx/PanelWidget.h
    ${SX_HEADER_DIRECTORY}/sx/Scene.h
    ${SX_HEADER_DIRECTORY}/sx/Shape.h
    ${SX_HEADER_DIRECTORY}/sx/SliderWidget.h
    ${SX_HEADER_DIRECTORY}/sx/TextShape.h
    ${SX_HEADER_DIRECTORY}/sx/Types.h
    ${SX_HEADER_DIRECTORY}/sx/Visitors.h
    ${SX_HEADER_DIRECTORY}/sx/Widget.h

    ${SX_SOURCE_DIRECTORY}/ButtonWidget.cpp
    ${SX_SOURCE_DIRECTORY}/CheckboxWidget.cpp
    ${SX_SOURCE_DIRECTORY}/Model.cpp
    ${SX_SOURCE_DIRECTORY}/Node.cpp
    ${SX_SOURCE_DIRECTORY}/PanelWidget.cpp
    ${SX_SOURCE_DIRECTORY}/Scene.cpp
    ${SX_SOURCE_DIRECTORY}/Shape.cpp
    ${SX_SOURCE_DIRECTORY}/SliderWidget.cpp
    ${SX_SOURCE_DIRECTORY}/TextShape.cpp
    ${SX_SOURCE_DIRECTORY}/Widget.cpp
)


SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES 
	ARCHIVE_OUTPUT_DIRECTORY  ${SX_BINARY_DIRECTORY}
)
# ----------------------------------------</ sceneExpression >




###########################################
# APPS
###########################################

ADD_SUBDIRECTORY( apps/examples/shapesExample )
ADD_SUBDIRECTORY( apps/examples/widgetExample )

